<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>新增管理员</title>
<link rel="stylesheet" href="../../bootstrap/css/bootstrap.min.css">
<script type="text/javascript" src="../../js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../../bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../../js/bootbox.min.js"></script>
</head>
<body class="container">
	<div class=" panel panel-warning ">
		<div class="panel-heading">
			<h3 class="panel-title">新增管理员</h3>
		</div>
		<div class="panel-body">
			<form id="addForm" class="form-horizontal">
				<div class="form-group">
					<label class="col-xs-2 control-label">用户名</label>
					<div class="col-xs-10">
						<input type="text" class="form-control" name="username" placeholder="您填写的用户名只能是字母和数字长度必须在4到25之间" autofocus pattern="^\w{4,25}$" required>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-2 control-label">密码</label>
					<div class="col-xs-10">
						<input type="password" class="form-control" name="password" placeholder="您填写的密码只能是字母和数字长度必须在4到25之间" pattern="^\w{4,25}$" required>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-2 control-label">姓名</label>
					<div class="col-xs-10">
						<input type="text" class="form-control" name="name" placeholder="姓名" required>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-2 control-label">权限</label>
					<div class="col-xs-10">
						<div class="col-xs-6 radio">
							<label> <input type="radio" name="qx" id="opQx1" value="1" checked>普通管理员
							</label>
						</div>
						<div class="col-xs-6 radio">
							<label> <input type="radio" name="qx" id="opQx2" value="2"> 高级管理员
							</label>
						</div>
					</div>
				</div>
				<div class="form-group">
					<button id="btnAdd" class="btn btn-info btn-block" type="submit">新增</button>
				</div>
			</form>
		</div>
	</div>
	<script type="text/javascript">
		$(function() {

			var qx;
			$.ajax({
				url : "../../adminsession",
				async : false,
				type : "GET"
			}).done(function(result) {
				qx = result;
			});
			$("#addForm").submit(function() {
				var username = $("input[name=username]").val();
				var password = $("input[name=password]").val();
				var name = $("input[name=name]").val();
				var qx = $("input[name=qx]:checked").val();
				var admin = {
					username : username,
					password : password,
					name : name,
					qx : qx,
				};
				$.ajax({
					url : "../../admin",
					type : "POST",
					data : JSON.stringify(admin),
					headers : {
						"Content-Type" : "application/json",
						"charset" : "utf-8"
					}
				}).done(function(result) {
					if (result == 'success') {
						window.location.href = "addsuccess.html";
					} else {
						bootbox.alert(result);
					}
				});
				return false;
			});

		});
	</script>
</body>
</html>